import type {
  PageResp,
  AdminResponseDto,
  CreateAdminDto,
  GetUserDetailDto,
  UpdateAdminRequestDto,
  DeleteAdminRequestDto
} from '@/types/api';
import type { TenantInfo } from '@/types/permission';
import request from '@/utils/request';

// 管理员查询参数接口
export interface AdminQueryParams {
  limit?: number;
  page?: number;
  status?: string;
  adminType?: string;
  name?: string;
}

// 管理员管理API
export const adminApi = {
  // 获取管理员列表
  getAdmins: async (params?: AdminQueryParams): Promise<PageResp> => {
    return await request.get('/admin/admins', { params });
  },

  // 创建管理员
  createAdmin: async (data: CreateAdminDto): Promise<AdminResponseDto> => {
    return await request.post('/admin/admins', data);
  },

  // 获取管理员详情
  getAdminDetail: async (data: GetUserDetailDto): Promise<AdminResponseDto> => {
    return await request.post('/admin/admins/detail', data);
  },

  // 更新管理员
  updateAdmin: async (data: UpdateAdminRequestDto): Promise<AdminResponseDto> => {
    return await request.post('/admin/admins/update', data);
  },

  // 删除管理员
  deleteAdmin: async (data: DeleteAdminRequestDto): Promise<void> => {
    return await request.post('/admin/admins/delete', data);
  },

  // 获取当前管理员可用的租户列表
  getMyTenants: async (): Promise<{ data: TenantInfo[] }> => {
    return await request.get('/admin/tenants');
  }
};
